import {
  Body,
  ClassSerializerInterceptor,
  Controller,
  Get,
  Param,
  ParseIntPipe,
  Post,
  Req,
  UseInterceptors,
} from '@nestjs/common';
import { ApiBearerAuth, ApiBody, ApiResponse, ApiTags } from '@nestjs/swagger';
import { CreateLiveDto } from './dto/create-live.dto';
import { Id } from './dto/id';
import { UpdateLiveDto } from './dto/updata-live.dto';
import { Live } from './entities/live.entity';
import { LiveService } from './live.service';

@ApiTags('房间相关')
@ApiBearerAuth()
@Controller('live')
export class LiveController {
  constructor(private readonly liveService: LiveService) {}

  @ApiBody({ type: CreateLiveDto })
  @ApiResponse({ type: Live })
  @UseInterceptors(ClassSerializerInterceptor)
  @Post('create')
  async create(@Body() createLiveDto: CreateLiveDto, @Req() request: any) {
    const user = request.user;
    return await this.liveService.create(createLiveDto, user);
  }

  @ApiBody({ type: UpdateLiveDto })
  @ApiResponse({ type: Live })
  @Post('update')
  async update(@Body() updateUserDto: UpdateLiveDto) {
    return this.liveService.update(updateUserDto.id, updateUserDto);
  }

  @ApiBody({ type: Id })
  @Post('delete')
  async remove(@Body() id: Id) {
    return this.liveService.remove(id.id);
  }

  // @ApiBody({})
  // @ApiResponse({ type :A })
  @Post('all')
  async all() {
    return await this.liveService.findAll();
  }

  @ApiBody({ type: Id })
  @ApiResponse({ type: Live })
  @UseInterceptors(ClassSerializerInterceptor)
  @Post('live')
  async fondOne(@Body() id: Id) {
    return this.liveService.findOne(id.id);
  }
}
